Inside Macintosh: Sound

| Previous | Chapter contents | Chapter top | Section top | Next |

The Common Chunk

Every AIFF and AIFF-C file must contain a Common Chunk that defines some fundamental characteristics of the sampled sound contained in the file. Note that the format of the Common Chunk is different for AIFF and AIFF-C files. As a result, you need to determine the type of file format (by inspecting the formType field of the Form Chunk) before reading the Common Chunk.

For AIFF files, the Common Chunk has this structure:

TYPE CommonChunk =
RECORD
    ckID:                   ID;             {'COMM'}
    ckSize:                 LongInt;        {size of chunk data}
    numChannels:            Integer;        {number of channels}
    numSampleFrames:        LongInt;        {number of sample frames}
    sampleSize:             Integer;        {number of bits per sample}
    sampleRate:             Extended;       {number of frames per second}
END;

For AIFF-C files, the Common Chunk has this structure:

TYPE ExtCommonChunk =
RECORD
    ckID:                   ID;             {'COMM'}
    ckSize:                 LongInt;        {size of chunk data}
    numChannels:            Integer;        {number of channels}
    numSampleFrames:        LongInt;        {number of sample frames}
    sampleSize:             Integer;        {number of bits per sample}
    sampleRate:             Extended;       {number of frames per second}
    compressionType:        ID;             {compression type ID}
    compressionName:        PACKED ARRAY[0..0] OF Byte;
                                            {compression type name}
END;

The fields that exist in both types of Common Chunk have the following meanings:

The numChannels field of both types of Common Chunk indicate the number of audio channels contained in the sampled sound. A value of 1 indicates monophonic sound, a value of 2 indicates stereo sound, a value of 4 indicates four-channel sound, and so forth. Any number of audio channels may be specified. The actual sound data is stored elsewhere, in the Sound Data Chunk.

The numSampleFrames field indicates the number of sample frames in the Sound Data Chunk. Note that this field contains the number of sample frames, not the number of bytes of data and not the number of sample points. For noncompressed sound data, the total number of sample points in the file is numChannels * numSampleFrames . (For more information on sample points, see "Sampled-Sound Data" .)

The sampleSize field indicates the number of bits in each sample point of noncompressed sound. Although the field can contain any integer from 1 to 32, the Sound Manager currently supports only 8- and 16-bit sound. For compressed sound data, this field indicates the number of bits per sample in the original sound data, before compression.

The sampleRate field contains the sample rate at which the sound is to be played back, in sample frames per second. For a list of common sample rates, see Table 1-2 .

An AIFF-C Common Chunk includes two fields that describe the type of compression (if any) used on the audio data. The compressionType field contains the type of the compression algorithm, if any, used on the sound data. Here are the currently available compression types and their associated compression names:

CONST
    {compression types}
    NoneType                        = 'NONE';
    ACE2Type                        = 'ACE2';
    ACE8Type                        = 'ACE8';
    MACE3Type                       = 'MAC3';
    MACE6Type                       = 'MAC6';

You can define your own compression types, but you should register them with Apple.

Finally, the compressionName field contains a human-readable name for the compression algorithm ID specified in the compressionType field. Compression names for Apple-supplied codecs are defined by constants:

CONST
    {compression names}
    NoneName                        = 'not compressed';
    ACE2to1Name                     = 'ACE 2-to-1';
    ACE8to3Name                     = 'ACE 8-to-3';
    MACE3to1Name                    = 'MACE 3-to-1';
    MACE6to1Name                    = 'MACE 6-to-1';

This string is useful when putting up alert boxes (perhaps because a necessary decompression routine is missing). Pad the end of this array with a byte having the value 0 if the length of this array is not an even number (but do not include the pad byte in the count).


© 1998 Apple Computer, Inc.

| Previous | Chapter contents | Chapter top | Section top | Next |